<template>
  <div style="min-height: 100vh;background:#f5f5f5;" class="addAddress">
    <van-address-edit
      :area-list="areaList"
      show-search-result
      show-delete
      :search-result="searchResult"
      :address-info="addressInfo"
      @focus="focus"
      @save="onSave"
      @change-area="changeArea"
      @change-detail="changeDetail"
      @delete="onDelete"/>
  </div>
</template>

<script>
  import address from "@/actions/area.js"
  import request from "@/actions/request.js"
  export default {
    name: "editAddress",
    components: {

    },
    data() {
      return {
        data:{},
        chosenAddressId: '1',
        list: [],
        areaList:address.areas,
        first_id:'',
        second_id:'',
        third_id:'',
        address:'',
        searchResult: [],
        addressInfo:{

        }
      }
    },
    watch:{

    },
    methods:{
      changeArea(values){
        this.first_id=values[0].code;
        this.second_id=values[1].code;
        this.third_id=values[2].code;
      },
      onSave(save) {
        request.editAddress(this,save)
      },
      onDelete() {
        request.deleteAddress(this)
      },
    },
    mounted() {
      this.first_id=this.$root.$mp.query.first_id;
      this.second_id=this.$root.$mp.query.second_id;
      this.third_id=this.$root.$mp.query.third_id;
      if(this.$root.$mp.query.addressId){
        this.addressInfo={
          name:this.$root.$mp.query.name,
          tel:this.$root.$mp.query.tel,
          addressDetail:this.$root.$mp.query.address,
          areaCode:this.$root.$mp.query.area,
          isDefault:!!(Number(this.$root.$mp.query.is_default)),
        }
      }
    },
  }
</script>

<style scoped lang="scss">

</style>
